from machine import Pin, I2C
from lib import *
import time
'''
i2c = I2C(scl=Pin(16), sda=Pin(17), freq=10000000)
display = sh1106.SH1106_I2C(128, 64, i2c, None, 0x3c)
display.invert(False)
display.rotate(True)
'''
def wifi():
    ssid_list = []
    ico(display, computer, 0, 108)
    fill(display, 0, 110, 10, 10, fill=0)
    ico(display, wifi_off, 0, 118)
    icodate(display, '0.0.0.0', 0, 0, fill=1)
    ftpp(display)
    if not wlan.isconnected():
        while True:
            rs = wlan.scan()
            for w in rs:ssid_list.append(w[0])
            for si in sipd:
                if si.encode() in ssid_list:
                    start_time = time.time()
                    wlan.connect(si, sipd[si])
                    while not wlan.isconnected():
                        if time.time()-start_time > 15:break
                else:continue
            if wlan.isconnected():break
    try:
        ntptime.settime()
        fill(display, 0, 110, 10, 10, fill=0)
        ico(display, wifi_on, 0, 118)
        display.show()
    except:
        pass

wifi()
fill(display, 0, 0, 35, 10, fill=0)
icodate(display, wlan.ifconfig()[0], 0, 0, fill=1)
display.show()

from lib.uftpd import *
start()